angular.module('${menuCode}')
.filter('to_trusted', ['$sce', function ($sce) {
	return function (text) {
	    return $sce.trustAsHtml(text);
	};
}])
.controller("${widgetCode}Ctrl",function($scope,AppKit,$ionicActionSheet,$stateParams,$state,$filter){
	$scope.piName=$stateParams.piName;
	$scope.loadProjTrackInfosData = function() {
		var url='/aeaipm/services/ProjTrack/rest/find-tracking-infos/'+$stateParams.piId+'/'+1;
		console.log(url)
		var promise = AppKit.getJsonApi(url);  
		promise.success(function(rspJson){
			$scope.trackInfos=rspJson.trackInfos;
			$scope.trackInfos=$filter('orderBy')($scope.trackInfos,'pwiName',true);
			
			$scope.tabPages = rspJson.rsListSize;
			$scope.tabCount = rspJson.trackListTotalSize;
			$scope.tabMores = true;
			
		});  
	}
	$scope.loadProjTrackInfosData();
	
	
	$scope.doReload = function(){
		$scope.tabPages = $scope.tabPages+1;
		var url='/aeaipm/services/ProjTrack/rest/find-tracking-infos/'+$stateParams.piId+'/'+$scope.tabPages;
		AppKit.getJsonApi(url).success(function(rspJson){
			
			if ($scope.tabCount >= $scope.tabPages){
				for (var i=0;i < rspJson.trackInfos.length;i++){
					var obj = rspJson.trackInfos[i];
					$scope.trackInfos.push(obj);				
				}	
				$scope.tabMores = true;
			}else{
				$scope.tabMores = false;
			}
		}).finally(function(){
			AppKit.reloadOver($scope);
		});
	} 
	
	$scope.hasMore = function(){
		return $scope.tabMores;
	}
	
/*	$scope.doRefresh=function(){
		$scope.weekNum++;
		$scope.loadProjTrackInfosData();
		AppKit.refreshOver($scope);
	}*/
});